package com.dmx.fw.util;

import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.beanutils.converters.DoubleConverter;
import org.apache.commons.beanutils.converters.FloatConverter;
import org.apache.commons.beanutils.converters.IntegerConverter;
import org.apache.commons.beanutils.converters.LongConverter;
import org.apache.commons.beanutils.converters.SqlDateConverter;
import org.apache.commons.beanutils.converters.StringConverter;
import org.apache.log4j.Logger;

public class DmxBeanUtils {
	
	public final static int INT_TYPE = 1;
    public final static int FLOAT_TYPE = 2;
    public final static int DOUBLE_TYPE = 3;
    public final static int STRING_TYPE = 4;
    public final static int DATE_TYPE = 5;
    public final static int SHORT_TYPE = 6;
    public final static int LONG_TYPE = 7;
    public final static int INTEGER_TYPE = 8;
    public final static int LONG_OBJECT_TYPE = 9;
    public final static int FLOAT_OBJECT_TYPE = 10;
    public final static int DOUBLE_OBJECT_TYPE = 11;

    /**
     * 所支持类型的转换器，待扩展
     */
    private static HashMap converters = new HashMap();

    /**
     *  getPropertyDescriptors 方法的缓存,以  class 为 key ,PropertyDescriptors[] 为值。
     */
    private static HashMap propertyDescriptorMap = new HashMap();

    private static HashMap valuesToMap;

    private static HashMap typesToMap;

    private static HashMap propertiesNamesCache= new HashMap();

    private static HashMap beanTypeCache=new HashMap();

    private static HashMap tableFieldNamesCache =new HashMap();

    private static Logger logger=null;

    private static HashMap typeMap=new HashMap();
    /**
     * 初始化常用类型的类型转换器。
     */
    static {
        converters.put(Double.TYPE, new DoubleConverter(new Double(0.0)));
        converters.put(Double.class, new DoubleConverter());
        converters.put(Float.TYPE, new FloatConverter(new Float(0.0f)));
        converters.put(Float.class, new FloatConverter());
        converters.put(Integer.TYPE, new IntegerConverter(new Integer(0)));
        converters.put(Integer.class, new IntegerConverter());
        converters.put(Long.TYPE, new LongConverter(new Long(0)));
        converters.put(Long.class, new LongConverter());
        converters.put(String.class, new StringConverter());
        converters.put(Date.class, new SqlDateConverter());
        logger=Logger.getLogger(DmxBeanUtils.class);

        typeMap.put("int", INT_TYPE + "");
        typeMap.put("float", FLOAT_TYPE + "");
        typeMap.put("double", DOUBLE_TYPE + "");
        typeMap.put("java.lang.String", STRING_TYPE + "");
        typeMap.put("java.util.Date", DATE_TYPE + "");
        typeMap.put("short", SHORT_TYPE + "");
        typeMap.put("long", LONG_TYPE + "");
        typeMap.put("java.lang.Integer", INTEGER_TYPE + "");
        typeMap.put("java.lang.Long", LONG_OBJECT_TYPE + "");
        typeMap.put("java.lang.Float", FLOAT_OBJECT_TYPE + "");
        typeMap.put("java.lang.Double", DOUBLE_OBJECT_TYPE + "");
    }

    public DmxBeanUtils() {
    }

    /**
     * 把字符串转为想要的Object
     *
     * @param value      String
     * @param targetType Class
     * @return Object
     * @throws Exception
     */
    public static Object convertStr2Obj(String value, Class targetType) throws
            Exception {
        Converter convert = (Converter) converters.get(targetType);

        if (convert == null) {
            throw new Exception("没有找到" + targetType + "的转换器。");
        }
        if(targetType==Date.class&&value.trim().length()>10){
           // return DateToStrUtils.StringToDate2(value);
        	return DateTimeUtils.getTimestamp(value, DateTimeUtils.getDateTimePattern());
        }
        return convert.convert(targetType, value.trim());

    }

    public static int getTypeId(Class clazz) {
        return Integer.parseInt(typeMap.get(clazz.getName()).toString().trim());
    }


    /**
     * 把bean中所有的null或"null"值转为""
     *
     * @param bean Object
     * @throws Exception
     */
    public static void convertBeanNullToString(Object bean) throws Exception {
        HashMap map = beanAndValuesToMap(bean);
        HashMap typeMap = beanAndTypesToMap(bean);
        String[] names = getBeanPropertyNames(bean);
        for (int i = 0; i < names.length; i++) {
            if ((Class) typeMap.get(names[i]) == String.class) {
                if ((String) map.get(names[i]) == null||(String) map.get(names[i]) =="null") {
                    map.remove(names[i]);
                    map.put(names[i], "");
                }
            }
        }
        org.apache.commons.beanutils.BeanUtils.populate(bean, map);

    }

    /**
     * 取得bean的属性描述信息，先从缓存中取，如没有则依bean的信息生成PropertyDescriptor。
     *
     * @param bean
     * @return  cached  PropertyDescriptor[]
     * @throws java.lang.Exception
     */
    public static PropertyDescriptor[] getBeanPropertyDescriptors(Object bean) throws Exception {

        PropertyDescriptor[] cached = (PropertyDescriptor[]) propertyDescriptorMap.get(bean.getClass());

        if (cached != null) {
            return cached;
        }
        
        cached = Introspector.getBeanInfo(bean.getClass(), Object.class).getPropertyDescriptors();
        propertyDescriptorMap.put(bean.getClass(), cached);
        return cached;

    }
    /**
     * 一般用实例一个表中的数据。比如设备中的子类，这就不要求用他的父类中的属性
     *
     */
    public static PropertyDescriptor[] getBeanPropertyDescriptors(Class clazz,Class beaseClass) throws Exception {
        String tableName=clazz.getName().substring(clazz.getName().lastIndexOf('.')+1);
        PropertyDescriptor[] cached = (PropertyDescriptor[]) propertyDescriptorMap.get(tableName);
        if (cached != null) {
            return cached;
        }
        //如果没有命中，可能是第一次访问。
        if (beaseClass!=null && beaseClass.isAssignableFrom(clazz)) {
            cached = Introspector.getBeanInfo(clazz,beaseClass).getPropertyDescriptors();
            propertyDescriptorMap.put(tableName, cached);
            return cached;
        }
        cached = Introspector.getBeanInfo(clazz, Object.class).getPropertyDescriptors();
        propertyDescriptorMap.put(tableName, cached);
        return cached;

    }
    public static void removeBeanPropertyDescriptors(String tableName) throws Exception {
        if(propertyDescriptorMap.containsKey(tableName)){
            propertyDescriptorMap.remove(tableName);
        }
    }
    public static void removeBeanPropertyDescriptors(Class clazz) throws Exception {
        if(propertyDescriptorMap.containsKey(clazz)){
            propertyDescriptorMap.remove(clazz);
        }
    }
    /**
     * 把sourceBean中的属性值拷到targetBean中
     *
     * @param sourceBean Object
     * @param targetBean Object
     * @throws Exception
     */
    public static void fill(Object sourceBean, Object targetBean) throws
            Exception {
        doFill(sourceBean, targetBean, false,false);
    }

    /**
     * 将拥有相同（相似）属性的Bean对象进行copy sourceBean--->targetBean
     * @param sourceBean Object
     * @param targetBean Object
     * @param exceptCollection boolean  为true表示不拷集合类型
     * @throws Exception
     */
    private static void doFill(Object sourceBean, Object targetBean,
                               boolean exceptCollection,boolean isobj2String) throws Exception {
        if (sourceBean == null || targetBean == null) {
            return;
        }

        // callbacks,  callback,hibernateLazyInitializer
        String soucePropertiesNames[] = getBeanPropertyNames(sourceBean);
        if (soucePropertiesNames != null) {
            final boolean isDebugEnabled = logger.isDebugEnabled();

            for (int i = 0; i < soucePropertiesNames.length; i++) {
                if(!soucePropertiesNames[i].equals("callbacks")&&!soucePropertiesNames[i].equals("callback")&&!soucePropertiesNames[i].equals("hibernateLazyInitializer")){
                    Object value = PropertyUtils.getProperty(sourceBean,soucePropertiesNames[i]);
                    try {
                        if (exceptCollection && value instanceof Collection ) {
                            if (isDebugEnabled) {
                                logger.debug("有一个属性" + soucePropertiesNames[i] +
                                        "是集合类型，所以没被赋值！");
                            }

                        } else {
                            if(isobj2String){
                                PropertyUtils.setProperty(targetBean,
                                        soucePropertiesNames[i],
                                        CommonUtils.converString2Valid(String.valueOf(value)));
                            }else{
                                PropertyUtils.setProperty(targetBean,
                                        soucePropertiesNames[i],
                                        value);
                            }

                        }
                    } catch (Exception ex) {
                        if (isDebugEnabled) {
                            logger.debug("有一个属性 " + soucePropertiesNames[i] + "=" +
                                    value + " 在目标bean中不存在");
                        }
                    }

                    // System.out.println("propertyName="+soucePropertiesNames[i]  +"    value="+value);


                }

            }

        }
    }


    /**
     * 将拥有相同（相似）属性的Bean对象进行copy 持久层对象 persistenceObject--->值对象valueObject
     * @param P_Object Object
     * @param V_Object Object
     * @throws Exception
     */
    public static void  convertPO2VO(Object P_Object, Object V_Object) throws Exception{
        fillSimple(P_Object, V_Object,true);

    }

    /**
     * 将拥有相同（相似）属性, 且在系统中处于同一层的Bean对象进行copy
     * @param sourceBean Object
     * @param targetBean Object
     * @throws Exception
     */
    public static void  convertPO2PO_OR_VO2VO(Object sourceBean, Object targetBean) throws Exception{
        fillSimple(sourceBean, targetBean,false);

    }

    /**
     * 将拥有相同（相似）属性的Bean对象进行copy sourceBean--->targetBean,但集合类型 的都不会转换
     * @param sourceBean Object
     * @param targetBean Object
     * @param isObj2String  boolean 是否将源对象的所有值转换为String 类型
     * @throws Exception
     */
    private static void fillSimple(Object sourceBean, Object targetBean,boolean isObj2String) throws
            Exception {
        doFill(sourceBean, targetBean, true,isObj2String);
    }

    /**
     * 取得bean的全部属性名，以数组的方式保存。
     *
     * @param bean
     * @return names String[]
     * @throws java.lang.Exception
     */
    public static String[] getBeanPropertyNames(Object bean) throws Exception {
        PropertyDescriptor[] fd = getBeanPropertyDescriptors(bean);
        String[]  propertyNames=(String [])propertiesNamesCache.get(bean.getClass());
        if(propertyNames!=null&&propertyNames.length>0){
            return  propertyNames;
        }
        propertyNames = new String[fd.length];
        for (int i = 0; i < propertyNames.length; i++) {
            propertyNames[i] = fd[i].getName();
        }
        propertiesNamesCache.put(bean.getClass(),propertyNames);
        return propertyNames;
    }
    public static String[] getBeanPropertyNames(Class clazz,Class baseClass) throws Exception {
        PropertyDescriptor[] fd = getBeanPropertyDescriptors(clazz,baseClass);
        String[] names = new String[fd.length];
        for (int i = 0; i < names.length; i++) {
            names[i] = fd[i].getName();
        }
        return names;
    }

    /**
     * 生成bean的属性名和值映射的map。
     *
     * @param bean  Object
     * @return valuesToMap    HashMap
     * @throws java.lang.Exception
     */
    public static HashMap beanAndValuesToMap(Object bean) throws Exception {
        PropertyDescriptor[] fd = getBeanPropertyDescriptors(bean);
        valuesToMap = new HashMap();
        for (int i = 0; i < fd.length; i++) {
            valuesToMap.put(fd[i].getName(),
                    PropertyUtils.getProperty(bean, fd[i].getName()));
        }
        return valuesToMap;
    }
    public static HashMap beanAndValuesToMap(Object bean,Class beasClass) throws Exception {
        PropertyDescriptor[] fd = getBeanPropertyDescriptors(bean.getClass(),beasClass);
        HashMap valuesToMap = new HashMap();
        for (int i = 0; i < fd.length; i++) {
            valuesToMap.put(fd[i].getName(),
                    PropertyUtils.getProperty(bean, fd[i].getName()));
        }
        return valuesToMap;
    }

    /**
     * 生成bean的属性名和类型映射的map。
     *
     * @param bean  Object
     * @return typesToMap HashMap
     * @throws java.lang.Exception
     */
    public static HashMap beanAndTypesToMap(Object bean) throws Exception {
        typesToMap=(HashMap)beanTypeCache.get(bean.getClass());
        if(typesToMap!=null&&typesToMap.size()>0){
            return  typesToMap;
        }
        PropertyDescriptor[] fd = getBeanPropertyDescriptors(bean);
        typesToMap = new HashMap();
        for (int i = 0; i < fd.length; i++) {
            typesToMap.put(fd[i].getName(),fd[i].getPropertyType());
        }
        beanTypeCache.put(bean.getClass(),typesToMap);
        return typesToMap;
    }
    public static HashMap beanAndTypesToMap(Class clazz,Class baseClass) throws Exception {
        PropertyDescriptor[] fd = getBeanPropertyDescriptors(clazz,baseClass);
        HashMap typesToMap = new HashMap();
        for (int i = 0; i < fd.length; i++) {
            typesToMap.put(fd[i].getName(),fd[i].getPropertyType());
        }
        return typesToMap;
    }

    /**
     * copy交集里的内容到子集
     *
     * @param father   Object
     * @param son   Object
     * @throws java.lang.Exception
     */
    public static void convertFatherToSon(Object father, Object son) throws
            Exception {
        HashMap map = beanAndValuesToMap(father);
        org.apache.commons.beanutils.BeanUtils.populate(son, map);
    }

    /**
     * 将表单form的值copy到POJO对象。
     *
     * @param source ActionForm
     * @param target Object
     * @throws Exception
     */
    public static void convert(Object source, Object target) throws
            Exception {
        String[] names = getBeanPropertyNames(source);
        for (int i = 0; i < names.length; i++) {
            convert(source, target, names[i]);
        }

    }
    public static void convert(Object source, Object target,Class clazz) throws
            Exception {
        String[] names = getBeanPropertyNames(source.getClass(),clazz);
        for (int i = 0; i < names.length; i++) {
            convert(source, target, names[i]);
        }
    }
    /**
     * 只将表单form的一列的值赋到表对象，如果form中的某属性输入值为null，则不进行转换
     *
     * @param source ActionForm
     * @param target Object
     * @param name   String
     * @throws NumberFormatException
     * @throws NoSuchMethodException
     * @throws java.lang.reflect.InvocationTargetException
     *
     * @throws IllegalAccessException
     * note 以前的版本为pubilc ,但整个系统中均无引用此方法，且如果只是对一个属性赋值，则可直接进行。
     */
    private static void convert(Object source, Object target,
                                String name) throws
            Exception {
        Object _value = null;
        try{
            _value = PropertyUtils.getProperty(source, name);
        }catch(Exception e)
        {
            _value = null;
        }
        //System.out.println("name: "+name+"    value:"+_value);
        if (_value == null) {
            return;
        }
        /*if(_value.getClass()==String.class && ((String)_value).trim().length()==0){
        	return;
        }*/
        final Class _targetType = PropertyUtils.getPropertyType(target,
                name);
        if (_targetType == null) {
            return;
        }
        final Class _soruceType = PropertyUtils.getPropertyType(source,
                name);
        if (_soruceType == _targetType) {
            PropertyUtils.setProperty(target, name, _value);
        } else {
            //下来_value只能是字符型，否则不符合规范
            //待扩展

            try {
                PropertyUtils.setProperty(target, name,
                        convertStr2Obj((String) _value,_targetType));
            }
            catch (Exception ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("值对象的属性"+_targetType+"转换失败，略过这个属性！");
                }

            }
        }
    }
    /**
     *将两个bean中不同名的属性赋值
     * @param source Object
     * @param target Object
     * @param targetFieldName   String
     * @throws NumberFormatException
     * @throws NoSuchMethodException
     * @throws java.lang.reflect.InvocationTargetException
     *
     * @throws IllegalAccessException
     */
    public  static void convert(Object source, Object target,
                                String sourceFieldName,String targetFieldName
    )throws Exception{
        final Object _value = PropertyUtils.getProperty(source, sourceFieldName);
        if (_value == null) {
            return;
        }
        if(_value instanceof String){
            if(_value.toString().equals(""))
                return;
        }
        final Class _targetType = PropertyUtils.getPropertyType(target,
                targetFieldName);
        if (_targetType == null) {
            return;
        }
        final Class _soruceType = PropertyUtils.getPropertyType(source,
                sourceFieldName);
        if (_soruceType == _targetType) {
            PropertyUtils.setProperty(target, targetFieldName, _value);
        } else {
            try {
                PropertyUtils.setProperty(target, targetFieldName,convertStr2Obj(String.valueOf(_value),_targetType));
            }
            catch (Exception ex) {
                System.out.println("值对象的属性"+_targetType+"转换失败，略过这个属性！");
            }
        }
    }


    /**
     * 将HashMap的内容填入bean中，对于POJO中的集合类型和POJO类型不作处理。
     * @param bean
     * @param subRs
     * @throws java.lang.Exception
     */
  /*  private static void fillHashMap(HashMap valueMap,Object bean) throws Exception {
        if (bean == null|| valueMap==null) {
            return;
        }
        HashMap map = new HashMap();
        String[] names = getBeanPropertyNames(bean);
        HashMap typeMap = beanAndTypesToMap(bean);
        Set keys=valueMap.keySet();

        final boolean isDebugEnabled = logger.isDebugEnabled();
        for (int i = 0; i < names.length; i++) {
            Object value = PropertyUtils.getProperty(bean,
                    names[i]);
            // System.out.println("feildName=  "+names[i]);
            if (value instanceof Collection ||value instanceof List ||value instanceof Set){
                if (isDebugEnabled) {
                    logger.debug("有一个属性" + names[i] +
                            "是集合类型，所以没被赋值！");
                }
            }else  if(typeMap.get(names[i]).toString().indexOf("com.bee.moss")>=0) {
                if(isDebugEnabled){
                    logger.debug("有一个属性" + names[i] +
                            "是一个POJO对象，所以没被赋值！");
                }
            }else if(keys.contains(names[i])){
                switch (getTypeId( (Class) typeMap.get(names[i]))) {
                    case DATE_TYPE:
                        try {
                            map.put(names[i],new java.util.Date());
                        }
                        catch (Exception ex) {
                            map.put(names[i], null);
                        }
                        break;
                    default:
                        map.put(names[i], valueMap.get(names[i]));
                        break;
                }
            }
            //待扩展

        }
        org.apache.commons.beanutils.BeanUtils.populate(bean, map);
    }*/

    /**
     * 把request中的各个值转成值对象，如果某个属性没有传则不对那个属性进行转换
     * @param request HttpServletRequest
     * @param bean Object
     * @throws Exception
     */
    /*public static void conver(HttpServletRequest request, Object bean) throws
            Exception {
        PropertyDescriptor[] fd = getBeanPropertyDescriptors(bean);
        final boolean isDebugEnabled = logger.isDebugEnabled();
        for (int i = 0; i < fd.length; i++) {
            final String _propertyName = fd[i].getName();
            final String _reqValue = request.getParameter(_propertyName);
            //只有request中有传才进行转换
            if (_reqValue != null&&!_reqValue.equals("null")) {
                try {
                    Object value = convertStr2Obj(_reqValue, fd[i].getPropertyType());
                    PropertyUtils.setProperty(bean, _propertyName, value);
                }
                catch (Exception ex) {
                    if (isDebugEnabled) {
                        logger.debug("值对象的属性"+_propertyName+"转换失败，略过这个属性！");
                    }

                }
            }
        }
    }*/

    /**
     * 从结果集中取出bean集合
     * @param bean
     * @param rs
     * @return
     * @throws java.lang.Exception
     */
    /*public static ArrayList getBeanCollection(Object bean, ResultSet rs) throws
            Exception {
        ArrayList al = new ArrayList();
        while (rs.next()) {
            al.add(getBeanFromResultSet(bean, rs));
        }
        return al;
    }*/

    /**
     * 将结果集转换成我们所需的bean
     * @param bean  Object
     * @param rs    ResultSet
     * @return object  Object
     * @throws java.lang.Exception
     */
   /* public static Object getBeanFromResultSet(Object bean, ResultSet rs) throws
            Exception {
        Object object = bean.getClass().newInstance();
        fillResultSetToObject(rs,object,true);
        return object;
    }*/


    /**
     * 将结果集转换成我们所需的子对象bean
     * @param subObject
     * @param rs
     * @return
     * @throws java.lang.Exception
     */
   /* public static Object getBeanSUBFromResultSet(Object subObject, ResultSet rs) throws
            Exception {
        fillResultSetToSUB(rs,subObject,true);
        return subObject;
    }*/


    /**
     * 将resultset的内容填入bean中，对于POJO中的集合类型没进行处理，一般的pojo则有赋对应的ID值，如果该POJO对应的表中含有该ID值。
     * @param bean
     * @param rs
     * @throws java.lang.Exception
     */
   /* private static void fillResultSetToObject(ResultSet rs,Object bean, boolean exceptCollection) throws Exception {
        if (bean == null|| rs==null) {
            return;
        }
        try{
            HashMap map = new HashMap();
            String[] names = getBeanPropertyNames(bean);
            HashMap typeMap = beanAndTypesToMap(bean);
            final boolean isDebugEnabled = logger.isDebugEnabled();
            Set columns=getFeildNameSet(rs,bean);
            for (int i = 0; i < names.length; i++) {
                //System.out.println(names[i]+"  "+typeMap.get(names[i]));
                Object value = PropertyUtils.getProperty(bean,
                        names[i]);
               //System.out.println(names[i]+"   " +rs.getString(names[i]));
                if (exceptCollection && (value instanceof Collection ||value instanceof List ||value instanceof Set))
                {
                    if (isDebugEnabled) {
                        logger.debug("有一个属性" + names[i] +
                                "是集合类型，所以没被赋值！");
                    }
                }else  if(typeMap.get(names[i]).toString().indexOf("com.icss.gdgx")>=0) {
                    //System.out.println(((Class)typeMap.get(names[i])).getName().replaceAll("/","."));
                    Object obj=Class.forName(((Class)typeMap.get(names[i])).getName().replaceAll("/",".")).newInstance();
                    String pojo_id=names[i].substring(0,1).toLowerCase()+names[i].substring(1)+"_id";
                    if(columns.contains(pojo_id.toUpperCase()) ){
                        long id=rs.getLong(pojo_id.toUpperCase());
                        if(id == 0L)
                            continue;
                        PropertyUtils.setProperty(obj, pojo_id,new Long(id)) ;
                        map.put(names[i],obj);
                        if(isDebugEnabled){
                            logger.debug("有一个属性" + names[i] +
                                    "是一个POJO对象，所以只被赋了主键值！");
                        }
                    }else{
                        logger.debug("有一个属性" + names[i] +
                                "是一个POJO对象，表中没有对应的字段！");
                    }
                }else {
                    if(columns.contains(names[i])){
                        switch (getTypeId( (Class) typeMap.get(names[i]))) {
                            case DATE_TYPE:
                                try {
                                    String date=rs.getString(names[i]);
                                    if(date.length()==10){
                                        map.put(names[i],
                                            new java.util.Date(rs.getDate(names[i]).getTime()));
                                    }else{
                                        map.put(names[i],
                                            DateToStrUtils.StringToDate2(date.substring(0,date.length()-2)));
                                    }
                                }
                                catch (Exception ex) {
                                    map.put(names[i], null);
                                }
                                break;
                            default:
                                try{
                                    map.put(names[i], rs.getString(names[i]));
                                }catch (Exception ex) {
                                    System.out.println("产生异常的列名:" + names[i]);
                                }
                                break;
                        }
                    }
                }
                //待扩展

            }
            org.apache.commons.beanutils.BeanUtils.populate(bean, map);
        }catch(Exception e){
            e.fillInStackTrace();
            throw(e);
        }
    }*/

    /**
     * 将resultset的内容填入bean中，对于POJO中的集合类型和POJO类型没作处理。
     * @param bean
     * @param subRs
     * @throws java.lang.Exception
     */
   /* private static void fillResultSetToSUB(ResultSet subRs,Object bean, boolean exceptCollection) throws Exception {
        if (bean == null|| subRs==null) {
            return;
        }
        HashMap map = new HashMap();
        String[] names = getBeanPropertyNames(bean);
        HashMap typeMap = beanAndTypesToMap(bean);
        Set columns=getFeildNameSet(subRs,bean);

        final boolean isDebugEnabled = logger.isDebugEnabled();
        for (int i = 0; i < names.length; i++) {
            Object value = PropertyUtils.getProperty(bean,
                    names[i]);
            // System.out.println("feildName=  "+names[i]);
            if (exceptCollection && (value instanceof Collection ||value instanceof List ||value instanceof Set))
            {
                if (isDebugEnabled) {
                    logger.debug("有一个属性" + names[i] +
                            "是集合类型，所以没被赋值！");
                }
            }else  if(typeMap.get(names[i]).toString().indexOf("com.whir.newsjjc")>=0) {
                if(isDebugEnabled){
                    logger.debug("有一个属性" + names[i] +
                            "是一个POJO对象，所以没被赋值！");
                }
            }else if(columns.contains(names[i].toUpperCase())){
                switch (getTypeId( (Class) typeMap.get(names[i]))) {
                    case DATE_TYPE:
                        try {
                            map.put(names[i],
                                    new java.util.Date(subRs.getDate(names[i]).getTime()));
                        }
                        catch (Exception ex) {
                            map.put(names[i], null);
                        }
                        break;
                    default:
                        map.put(names[i], subRs.getString(names[i]));
                        break;
                }
            }
            //待扩展

        }
        org.apache.commons.beanutils.BeanUtils.populate(bean, map);
    }*/
    /*public static Map findColumnName(ResultSet rs)throws Exception{
        ResultSetMetaData meta= rs.getMetaData();
        Map columnMap=new HashMap();
        for(int i=1,size=meta.getColumnCount();i<=size;i++){
            columnMap.put(meta.getColumnName(i), new Integer(i));
        }
        return columnMap;
    }

    public  static Set getFeildNameSet(ResultSet subRs,Object bean) throws Exception{
        Set tableFieldNamesSet=(Set)tableFieldNamesCache.get(bean.getClass()) ;
        if(tableFieldNamesSet!=null&&tableFieldNamesSet.size()>0) {
            return  tableFieldNamesSet;
        }
        tableFieldNamesSet = new HashSet();
        ResultSetMetaData rsmd = subRs.getMetaData();
        int numColumns = rsmd.getColumnCount();
        for (int i = 0; i < numColumns; i++) {
            tableFieldNamesSet.add(rsmd.getColumnName(i + 1));
        }
        tableFieldNamesCache.put(bean.getClass(),tableFieldNamesSet);
        return tableFieldNamesSet;
    }*/

}
